home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume2 / util / dutils.1 < prev    next >
Text File  |  1988-10-25  |  16KB  |  804 lines

  1. Path: xanth!nic.MR.NET!tank!ncar!mailrus!ulowell!page
  2. From: page@swan.ulowell.edu (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v02i026:  dutils - various small utilities
  5. Message-ID: <9861@swan.ulowell.edu>
  6. Date: 25 Oct 88 18:21:38 GMT
  7. Organization: University of Lowell, Computer Science Dept.
  8. Lines: 793
  9. Approved: page@swan.ulowell.edu
  10.  
  11. Submitted-by: dillon@cory.berkeley.edu (Matt Dillon)
  12. Posting-number: Volume 2, Issue 26
  13. Archive-name: util/dutils.1
  14.  
  15. # This is a shell archive.  Remove anything before this line
  16. # then unpack it by saving it in a file and typing "sh file"
  17. # (Files unpacked will be owned by you and have default permissions).
  18. # This archive contains the following files:
  19. #    Makefile
  20. #    addcr.c
  21. #    cmp.c
  22. #    com.doc
  23. #    findit.c
  24. #    libs.c
  25. #    remcr.c
  26. #    scat.c
  27. #
  28. if `test ! -s Makefile`
  29. then
  30. echo "writing Makefile"
  31. cat > Makefile << '\Rogue\Monster\'
  32.  
  33. #   Makefile for single-source-file utilities
  34.  
  35. SYMS=    include:symbols.m
  36. SYMC=    include:local/makesymbols.c
  37. CFLAGS= +L +I$(SYMS)
  38. LFLAGS= +Q
  39. DD=    srcc:
  40. OD=    T:
  41.  
  42. all:    $(DD)findit $(DD)libs $(DD)scat $(DD)addcr $(DD)remcr $(DD)cmp
  43.  
  44. $(DD)findit:    findit.c
  45.     cc $(CFLAGS) findit.c -o $(OD)findit.o
  46.     ln +Q $(OD)findit.o -lsup32 -lc32 -o $(DD)findit
  47.     delete $(OD)findit.o
  48.  
  49. $(DD)libs:      libs.c
  50.     cc $(CFLAGS) libs.c -o $(OD)libs.o
  51.     ln +Q $(OD)libs.o -lsup32 -lc32 -o $(DD)libs
  52.     delete $(OD)libs.o
  53.  
  54. $(DD)scat:      scat.c
  55.     cc $(CFLAGS) scat.c -o $(OD)scat.o
  56.     ln +Q $(OD)scat.o -lsup32 -lc32 -o $(DD)scat
  57.     delete $(OD)scat.o
  58.  
  59. $(DD)addcr:     addcr.c
  60.     cc $(CFLAGS) addcr.c -o $(OD)addcr.o
  61.     ln +Q $(OD)addcr.o -lsup32 -lc32 -o $(DD)addcr
  62.     delete $(OD)addcr.o
  63.  
  64. $(DD)remcr:     remcr.c
  65.     cc $(CFLAGS) remcr.c -o $(OD)remcr.o
  66.     ln +Q $(OD)remcr.o -lsup32 -lc32 -o $(DD)remcr
  67.     delete $(OD)remcr.o
  68.  
  69. $(DD)cmp:       cmp.c
  70.     cc $(CFLAGS) cmp.c -o $(OD)cmp.o
  71.     ln +Q $(OD)cmp.o -lsup32 -lc32 -o $(DD)cmp
  72.     delete $(OD)cmp.o
  73.  
  74. $(SYMS):    $(SYMC)
  75.     make -f include:local/Makefile
  76.  
  77. \Rogue\Monster\
  78. else
  79.   echo "will not over write Makefile"
  80. fi
  81. if [ `wc -c Makefile | awk '{printf $1}'` -ne 1109 ]
  82. then
  83. echo `wc -c Makefile | awk '{print "Got " $1 ", Expected " 1109}'`
  84. fi
  85. if `test ! -s addcr.c`
  86. then
  87. echo "writing addcr.c"
  88. cat > addcr.c << '\Rogue\Monster\'
  89.  
  90. /*
  91.  *  ADDCR.C
  92.  *
  93.  *  ADDCR [-l] file1 file2 ... filen
  94.  *
  95.  *  -l = convert filenames to lower case on writeout.
  96.  */
  97.  
  98. #include <stdio.h>
  99.  
  100. extern char *malloc();
  101.  
  102. main(ac,av)
  103. char *av[];
  104. {
  105.     register short i;
  106.     FILE *fi;
  107.     long len;
  108.     char *buf;
  109.     char *wbuf;
  110.     char clower = 0;
  111.  
  112.     for (i = 1; i < ac; ++i) {
  113.     if (strcmp(av[i], "-l") == 0) {
  114.         clower = 1;
  115.         continue;
  116.     }
  117.     printf("%-20s ", av[i]);
  118.     fflush(stdout);
  119.     if ((fi = fopen(av[i], "r")) == NULL) {
  120.         perror(av[i]);
  121.         continue;
  122.     }
  123.     fseek(fi, 0, 2);
  124.     len = ftell(fi);
  125.     printf("%6ld ", len);
  126.     fflush(stdout);
  127.     if (len < 0 || (buf = malloc(len*3)) == NULL) {
  128.         puts("len < 0 or malloc failed");
  129.         fclose(fi);
  130.         continue;
  131.     }
  132.     fseek(fi, 0, 0);
  133.     if (fread(buf, len, 1, fi) != 1) {
  134.         puts("read failed");
  135.         goto done;
  136.     }
  137.     fclose(fi);
  138.     wbuf = buf + len;
  139.     len = addcr(buf, len);
  140.     if (clower) {
  141.         register char *ptr;
  142.         for (ptr = av[i]; *ptr; ++ptr) {
  143.         if (*ptr >= 'A' && *ptr <= 'Z')
  144.             *ptr |= 0x20;
  145.         }
  146.     }
  147.     if ((fi = fopen(av[i], "w")) == NULL) {
  148.         puts("Unable to open for write");
  149.         goto done;
  150.     }
  151.     printf("write ");
  152.     fflush(stdout);
  153.     if (fwrite(wbuf, len, 1, fi) != 1) {
  154.         puts("write failed");
  155.         goto done;
  156.     }
  157.     puts("ok");
  158. done:
  159.     fclose(fi);
  160.     free(buf);
  161.     }
  162. }
  163.  
  164. addcr(buf, len)
  165. register char *buf;
  166. register long len;
  167. {
  168.     register char *ptr = buf + len;
  169.     register long i, j;
  170.     for (i = j = 0; i < len; ++i) {
  171.     if (buf[i] == 13)
  172.         continue;
  173.     if (buf[i] != 10) {
  174.         ptr[j++] = buf[i];
  175.         continue;
  176.     }
  177.     ptr[j++] = 13;
  178.     ptr[j++] = 10;
  179.     }
  180.     return(j);
  181. }
  182.  
  183. \Rogue\Monster\
  184. else
  185.   echo "will not over write addcr.c"
  186. fi
  187. if [ `wc -c addcr.c | awk '{printf $1}'` -ne 1586 ]
  188. then
  189. echo `wc -c addcr.c | awk '{print "Got " $1 ", Expected " 1586}'`
  190. fi
  191. if `test ! -s cmp.c`
  192. then
  193. echo "writing cmp.c"
  194. cat > cmp.c << '\Rogue\Monster\'
  195.  
  196. /*
  197.  * CMP.C
  198.  *
  199.  *
  200.  * (C)Copyright 1986, Matthew Dillon, All Rights Reserved.
  201.  * Permission is granted to distribute for non-profit only.
  202.  *
  203.  *    comp file1 file2
  204.  *
  205.  *    Compare two files.  The program will tell you if two files compare
  206.  *    the same or, if not, where the error occured.
  207.  *
  208.  */
  209.  
  210. #include <stdio.h>
  211. #include <fcntl.h>
  212.  
  213. extern char *malloc();
  214.  
  215. #define BUFSIZE   16384
  216.  
  217. main(ac, av)
  218. char *av[];
  219. {
  220.     long f1, f2;
  221.     register short i, j, n;
  222.     char fail;
  223.     char *buf1, *buf2;
  224.     char *premature_eof = "premature EOF in %s (files compare to that point)\n";
  225.  
  226.     buf1 = malloc(BUFSIZE);
  227.     buf2 = malloc(BUFSIZE);
  228.     if (!buf1 || !buf2) {
  229.     puts("no memory");
  230.     exit(30);
  231.     }
  232.     fail = 0;
  233.     if (ac <= 2) {
  234.     puts ("V2.00 (c)Copyright 1986-1988 Matthew Dillon, All Rights Reserved");
  235.     puts ("cmp file1 file2");
  236.     exit(0);
  237.     }
  238.     f1 = open(av[1], O_RDONLY);
  239.     f2 = open(av[2], O_RDONLY);
  240.     if (f1 && f2) {
  241.     while (!fail && (i = read(f1, buf1, 256))) {
  242.         n = read(f2, buf2, i);
  243.         if (!bcmp(buf1, buf2, n))
  244.         fail = 5;
  245.         if (!fail) {
  246.         if (n == i)
  247.             continue;
  248.         fail = 5;
  249.         }
  250.     }
  251.     if (!fail && read(f2, buf2, 1))
  252.         fail = 5;
  253.     } else {
  254.     puts("Could not open both files");
  255.     fail = 20;
  256.     }
  257.     if (f1 >= 0)
  258.     close(f1);       /* f1 & f2 are either valid or NULL */
  259.     if (f2 >= 0
  260.     close(f2);
  261.     if (fail)
  262.     puts("Compare failed");
  263.     exit(fail);
  264. }
  265.  
  266.  
  267. \Rogue\Monster\
  268. else
  269.   echo "will not over write cmp.c"
  270. fi
  271. if [ `wc -c cmp.c | awk '{printf $1}'` -ne 1398 ]
  272. then
  273. echo `wc -c cmp.c | awk '{print "Got " $1 ", Expected " 1398}'`
  274. fi
  275. if `test ! -s com.doc`
  276. then
  277. echo "writing com.doc"
  278. cat > com.doc << '\Rogue\Monster\'
  279.  
  280.      (c)Copyright 1988, Matthew Dillon, All Rights Reserved
  281.            Freely Distributable for non-profit only
  282.  
  283.  
  284.                      ADDCR
  285.  
  286.                  V1.00, 16 October 1988
  287.  
  288. ADDCR <files>
  289.  
  290.     Each file specified is loaded into ram, CR's added before LF's, and
  291.     written back out under the same name.
  292.  
  293.                       CMP
  294.  
  295.                  V1.00, 16 October 1988
  296.  
  297. CMP file1 file2
  298.  
  299.     The two files must be of the same size.  The files are compared for
  300.     exact equality.  An error message is displayed if the files do not
  301.     compare.  Exit value:
  302.  
  303.         0    compare successful
  304.         5    compare failed
  305.         20    unable to open both files
  306.         30    unable to allocate memory!
  307.  
  308.  
  309.                      FINDIT
  310.  
  311.                  V1.00, 16 October 1988
  312.  
  313. FINDIT [-ddir] <wildcard> <wildcard> ...
  314.  
  315.     Search the specified directories for files matching the
  316.     given wildcard.
  317.  
  318.     If no directories are specified, look for a directory list
  319.     in the ENV: enviroment variable FINDITVOLS, of the form:
  320.  
  321.     dir,dir,dir ...
  322.  
  323.     After setting up such an enviroment variable, FINDIT is as
  324.     simple as 'FINDIT <wildcard>'.  Example:
  325.  
  326.     findit list
  327.     findit l\*    (from a shell)
  328.     findit l*    (from a CLI)
  329.  
  330.     The * and ? wildcards are supported.
  331.  
  332.  
  333.                      LIBS
  334.  
  335.                   V1.00, 16 October 1988
  336.  
  337.  
  338. LIBS    [libname]
  339.  
  340.     With no arguments lists libraries and devices currently in
  341.     memory, their version, and the number of references.
  342.  
  343.     If a library name is given as a reference and that library
  344.     has no references it will be removed.  If the library has
  345.     references the delayed-expunge flag is set and the library
  346.     will be removed when the references fall to 0.
  347.  
  348.     This utility is useful for those of us working on our own
  349.     custom libraries.
  350.  
  351. Example:
  352.  
  353.     libs
  354.     libs dres.library
  355.  
  356.                      REMCR
  357.  
  358.                  V1.00, 16 October 1988
  359.  
  360. REMCR <files>
  361.  
  362.     Each file specified is loaded into ram, CR's removed, and written
  363.     back out under the same name.
  364.  
  365.  
  366.                      SCAT
  367.  
  368.                   V1.00, 16 October 1988
  369.  
  370. SCAT <files>
  371.  
  372.     Like cat, but non-ascii characters are displayed in reverse.
  373.  
  374.  
  375.  
  376. \Rogue\Monster\
  377. else
  378.   echo "will not over write com.doc"
  379. fi
  380. if [ `wc -c com.doc | awk '{printf $1}'` -ne 2021 ]
  381. then
  382. echo `wc -c com.doc | awk '{print "Got " $1 ", Expected " 2021}'`
  383. fi
  384. if `test ! -s findit.c`
  385. then
  386. echo "writing findit.c"
  387. cat > findit.c << '\Rogue\Monster\'
  388.  
  389. /*
  390.  *  FINDIT()
  391.  *
  392.  *  FINDIT [-ddir] <programname> <programname> ...
  393.  *
  394.  *  Search specified directories (those specified in FINDITVOLS if none
  395.  *  spcified on the command line) for the specified program names.  Wildcards
  396.  *  are acceptable
  397.  *
  398.  *  Format for FINDITVOLS:    dir,dir,dir ...
  399.  */
  400.  
  401. #include <local/typedefs.h>
  402. #include <local/xmisc.h>
  403. #include <stdio.h>
  404.  
  405. #define ENVVAR    "FINDITVOLS"
  406.  
  407. MLIST    DList;
  408. MLIST    FList;
  409. char *ErrorString = "unable to open dres.library";
  410. char *EnvStr;
  411. char Path[1024];
  412.  
  413. extern int Enable_Abort;
  414.  
  415. main(ac,av)
  416. char *av[];
  417. {
  418.     NewList(&DList);
  419.     NewList(&FList);
  420.  
  421.     Enable_Abort = 0;
  422.     {
  423.     register short i;
  424.     for (i = 1; i < ac; ++i) {
  425.         register char *str = av[i];
  426.         if (*str != '-') {
  427.         register NODE *node = malloc(sizeof(NODE));
  428.         node->ln_Name = str;
  429.         AddTail(&FList, node);
  430.         continue;
  431.         }
  432.         for (++str; *str; ++str) {
  433.         switch(*str) {
  434.         case 'd':
  435.             {
  436.             register NODE *node = malloc(sizeof(NODE));
  437.             node->ln_Name = str + 1;
  438.             AddTail(&DList, node);
  439.             }
  440.             str = "\0";
  441.             break;
  442.         default:
  443.             printf("Unknown option: -%c\n", *str);
  444.             exit(1);
  445.         }
  446.         }
  447.     }
  448.     }
  449.     if (openlibs(DRES_LIB) == 0) {
  450.     puts(ErrorString);
  451.     exit(1);
  452.     }
  453.     mountrequest(0);
  454.     if (!GetHead(&DList)) {         /*  scan enviroment variable for dirs */
  455.     char *str;
  456.     register char *ptr;
  457.     register NODE *node;
  458.     register char c;
  459.  
  460.     str = EnvStr = GetDEnv(ENVVAR);
  461.     if (!str) {
  462.         printf("Env. Var %s not found, format:  dir,dir,dir...\n", ENVVAR);
  463.         goto fail;
  464.     }
  465.     for (c = 1; c; str = ptr + 1) {
  466.         for (ptr = str; *ptr && *ptr != ','; ++ptr);
  467.         c = *ptr;
  468.         *ptr = 0;
  469.         node = malloc(sizeof(NODE));
  470.         node->ln_Name = str;
  471.         AddTail(&DList, node);
  472.     }
  473.     }
  474.     {
  475.     register NODE *node;
  476.     register FIB *fib = malloc(sizeof(FIB));
  477.     while (node = RemHead(&DList)) {
  478.         long lock;
  479.  
  480.         if (lock = Lock(node->ln_Name, SHARED_LOCK)) {
  481.         strcpy(Path, node->ln_Name);
  482.         if (Examine(lock, fib))
  483.             SearchTree(lock, fib, strlen(Path));
  484.         UnLock(lock);
  485.         }
  486.         free(node);
  487.         if (checkbreak())
  488.         break;
  489.     }
  490.     free(fib);
  491.     puts("");
  492.     }
  493. fail:
  494.     if (checkbreak())
  495.     puts("^C");
  496.     {
  497.     register NODE *node;
  498.     while (node = RemHead(&DList))
  499.         free(node);
  500.     while (node = RemHead(&FList))
  501.         free(node);
  502.     }
  503.     if (EnvStr)
  504.     free(EnvStr);
  505.     mountrequest(1);
  506.     closelibs(-1);
  507. }
  508.  
  509. /*
  510.  *  Search the specified directory for the wildcarded names in FList.
  511.  */
  512.  
  513. SearchTree(dirlock, dirfib, idx)
  514. long dirlock;
  515. FIB *dirfib;
  516. {
  517.     long oldlock;
  518.     long lock;
  519.     register FIB *fib = malloc(sizeof(FIB));
  520.  
  521.     oldlock = CurrentDir(dirlock);
  522.     while (ExNext(dirlock, dirfib)) {
  523.     if (idx && Path[idx-1] != ':' && Path[idx-1] != '/') {
  524.         Path[idx] = '/';
  525.         strcpy(Path+idx+1, dirfib->fib_FileName);
  526.     } else {
  527.         strcpy(Path+idx, dirfib->fib_FileName);
  528.     }
  529.     if (dirfib->fib_DirEntryType > 0) {
  530.         if (lock = Lock(dirfib->fib_FileName, SHARED_LOCK)) {
  531.         if (Examine(lock, fib))
  532.             SearchTree(lock, fib, idx + strlen(Path+idx));
  533.         UnLock(lock);
  534.         if (checkbreak())
  535.             break;
  536.         }
  537.     } else {
  538.         register NODE *node;
  539.         for (node = GetHead(&FList); node; node = GetSucc(node)) {
  540.         if (WildCmp(node->ln_Name, dirfib->fib_FileName)) {
  541.             printf("%s ", Path);
  542.             fflush(stdout);
  543.         }
  544.         }
  545.     }
  546.     }
  547.     CurrentDir(oldlock);
  548.     free(fib);
  549. }
  550.  
  551. \Rogue\Monster\
  552. else
  553.   echo "will not over write findit.c"
  554. fi
  555. if [ `wc -c findit.c | awk '{printf $1}'` -ne 3332 ]
  556. then
  557. echo `wc -c findit.c | awk '{print "Got " $1 ", Expected " 3332}'`
  558. fi
  559. if `test ! -s libs.c`
  560. then
  561. echo "writing libs.c"
  562. cat > libs.c << '\Rogue\Monster\'
  563.  
  564. /*
  565.  *  LIBS.C
  566.  *
  567.  *  Libs [libname]
  568.  *
  569.  *  Libs        - list currently loaded libraries
  570.  *  Libs dres.library    - expunge specified lib on last close if no
  571.  *              further opens
  572.  */
  573.  
  574. #include <local/typedefs.h>
  575.  
  576. extern EXECBASE *SysBase;
  577.  
  578. main(ac,av)
  579. char *av[];
  580. {
  581.     short i;
  582.     LIB *lib;
  583.  
  584.     if (ac == 1) {
  585.     NODE *node;
  586.     for (node = SysBase->LibList.lh_Head; node->ln_Succ; node = node->ln_Succ) {
  587.         printf("%-20s ver %3ld  refs %ld\n",
  588.         node->ln_Name,
  589.         ((LIB *)node)->lib_Version,
  590.         ((LIB *)node)->lib_OpenCnt
  591.         );
  592.     }
  593.     puts("");
  594.     for (node = SysBase->DeviceList.lh_Head; node->ln_Succ; node = node->ln_Succ) {
  595.         printf("%-20s ver %3ld  refs %ld\n",
  596.         node->ln_Name,
  597.         ((LIB *)node)->lib_Version,
  598.         ((LIB *)node)->lib_OpenCnt
  599.         );
  600.     }
  601.     }
  602.     for (i = 1; i < ac; ++i) {
  603.     lib = OpenLibrary(av[i], 0);
  604.     if (lib) {
  605.         RemLibrary(lib);
  606.         printf("library refs: %ld\n", lib->lib_OpenCnt - 1);
  607.         puts("Will expunge on last close if no new opens");
  608.         CloseLibrary(lib);
  609.     } else {
  610.         puts("Unable to open library");
  611.     }
  612.     }
  613. }
  614.  
  615. \Rogue\Monster\
  616. else
  617.   echo "will not over write libs.c"
  618. fi
  619. if [ `wc -c libs.c | awk '{printf $1}'` -ne 1045 ]
  620. then
  621. echo `wc -c libs.c | awk '{print "Got " $1 ", Expected " 1045}'`
  622. fi
  623. if `test ! -s remcr.c`
  624. then
  625. echo "writing remcr.c"
  626. cat > remcr.c << '\Rogue\Monster\'
  627.  
  628. /*
  629.  *  REMCR.C
  630.  *
  631.  *  REMCR [-l]    file1 file2 ... filen
  632.  *
  633.  *  -l    : convert file name to lower case
  634.  *
  635.  */
  636.  
  637. #include <stdio.h>
  638.  
  639. extern char *malloc();
  640.  
  641. main(ac,av)
  642. char *av[];
  643. {
  644.     register short i;
  645.     FILE *fi;
  646.     long len;
  647.     char *buf;
  648.     char clower = 0;
  649.  
  650.     for (i = 1; i < ac; ++i) {
  651.     if (strcmp(av[i], "-l") == 0) {
  652.         clower = 1;
  653.         continue;
  654.     }
  655.     printf("%-20s ", av[i]);
  656.     fflush(stdout);
  657.     if ((fi = fopen(av[i], "r")) == NULL) {
  658.         perror(av[i]);
  659.         continue;
  660.     }
  661.     fseek(fi, 0, 2);
  662.     len = ftell(fi);
  663.     printf("%6ld ", len);
  664.     fflush(stdout);
  665.     if (len < 0 || (buf = malloc(len*2)) == NULL) {
  666.         puts("len < 0 or malloc failed");
  667.         fclose(fi);
  668.         continue;
  669.     }
  670.     fseek(fi, 0, 0);
  671.     if (fread(buf, len, 1, fi) != 1) {
  672.         puts("read failed");
  673.         goto done;
  674.     }
  675.     fclose(fi);
  676.     len = remcr(buf, len);
  677.     if (clower) {
  678.         register char *ptr;
  679.         for (ptr = av[i]; *ptr; ++ptr) {
  680.         if (*ptr >= 'A' && *ptr <= 'Z')
  681.             *ptr |= 0x20;
  682.         }
  683.     }
  684.     if ((fi = fopen(av[i], "w")) == NULL) {
  685.         puts("Unable to open for write");
  686.         goto done;
  687.     }
  688.     printf("write ");
  689.     fflush(stdout);
  690.     if (fwrite(buf, len, 1, fi) != 1) {
  691.         puts("write failed");
  692.         goto done;
  693.     }
  694.     puts("ok");
  695. done:
  696.     fclose(fi);
  697.     free(buf);
  698.     }
  699. }
  700.  
  701. remcr(buf, len)
  702. register char *buf;
  703. register long len;
  704. {
  705.     register char *ptr = buf + len;
  706.     register long i, j;
  707.     for (i = j = 0; i < len; ++i) {
  708.     if (buf[i] == 13)
  709.         continue;
  710.     ptr[j++] = buf[i];
  711.     }
  712.     bmov(buf + len, buf, j);
  713.     return(j);
  714. }
  715.  
  716. \Rogue\Monster\
  717. else
  718.   echo "will not over write remcr.c"
  719. fi
  720. if [ `wc -c remcr.c | awk '{printf $1}'` -ne 1494 ]
  721. then
  722. echo `wc -c remcr.c | awk '{print "Got " $1 ", Expected " 1494}'`
  723. fi
  724. if `test ! -s scat.c`
  725. then
  726. echo "writing scat.c"
  727. cat > scat.c << '\Rogue\Monster\'
  728.  
  729. #include <stdio.h>
  730. #include <ctype.h>
  731.  
  732. main(ac, av)
  733. char *av[];
  734. {
  735.     register int i;
  736.     register FILE *stream;
  737.  
  738.     for (i = 1; i < ac; ++i) {
  739.     stream = fopen(av[i], "r");
  740.     if (stream) {
  741.         scat(stream);
  742.         fclose(stream);
  743.     } else {
  744.         fprintf(stderr, "Unable to open %s\n", av[i]);
  745.     }
  746.     }
  747.     if (ac == 1)
  748.     scat(stdin);
  749. }
  750.  
  751. scat(stream)
  752. FILE *stream;
  753. {
  754.     short c;
  755.  
  756.     while ((c = fgetc(stream)) >= 0) {
  757.     if (isascii(c) && isprint(c)) {
  758.         reverse(0);
  759.         putc(c, stdout);
  760.         continue;
  761.     }
  762.     reverse(1);
  763.     putc((c|0x40)&0x7F, stdout);
  764.     if (c == '\n')
  765.         putc(c, stdout);
  766.     }
  767.     reverse(0);
  768. }
  769.  
  770. reverse(mode)
  771. {
  772.     static char xmode;
  773.  
  774.     if (mode) {
  775.     if (!xmode) {
  776.         putc(0x9b, stdout);
  777.         putc(0x37, stdout);
  778.         putc('m', stdout);
  779.     }
  780.     } else {
  781.     if (xmode) {
  782.         putc(0x9b, stdout);
  783.         putc(0x30, stdout);
  784.         putc('m', stdout);
  785.     }
  786.     }
  787.     xmode = mode;
  788. }
  789.  
  790. \Rogue\Monster\
  791. else
  792.   echo "will not over write scat.c"
  793. fi
  794. if [ `wc -c scat.c | awk '{printf $1}'` -ne 892 ]
  795. then
  796. echo `wc -c scat.c | awk '{print "Got " $1 ", Expected " 892}'`
  797. fi
  798. echo "Finished archive 1 of 1"
  799. # if you want to concatenate archives, remove anything after this line
  800. exit
  801. -- 
  802. Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
  803. Have five nice days.
  804.